//
//  ZH_ConfirmOrdrViewController.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/12.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_ConfirmOrdrViewController.h"
#import "ZH_HomeCourceTableViewCell.h"
#import "ZH_PaymentViewController.h"
@interface ZH_ConfirmOrdrViewController ()<UITableViewDelegate,UITableViewDataSource>

///底部View
@property (nonatomic, weak) UIView *bottomView;
///删除
@property (nonatomic, weak) UIButton *deleteButton;
///合计
@property (nonatomic, weak) UILabel *totalLabel;
@property (nonatomic,weak)UITableView *tableView;
@end

@implementation ZH_ConfirmOrdrViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUserInterface];
}

- (void)initUserInterface{
    self.navigationItem.title = @"确认订单";
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.height.mas_equalTo(HEIGHT_TRANSFORMATION(98));
    }];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(FITSCALE(0));
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([self.type isEqualToString:@"1"]) {
        return 1;
    }
    return self.models.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZH_HomeCourceTableViewCell *cell = [ZH_HomeCourceTableViewCell cellWithTableView:tableView];
    if ([self.type isEqualToString:@"1"]) {
        [cell updatesUI:self.dic];
    }
    else{
       [cell updataUI:self.models[indexPath.row]];
    }
    return cell;
}
- (void)onDeleteBlock:(UIButton *)btn{
    ZH_PaymentViewController *vc = [[ZH_PaymentViewController alloc] init];
    vc.trade = self.trade;
    vc.sign = self.sign;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - getter,setter
- (UITableView *)tableView{
    if(!_tableView){
        UITableView *tableView = [UITableView createTableViewWithDelegateTarget:self];
        tableView.backgroundColor = kCommonBackgroudColor;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [tableView setCellAutoAdaptationForEstimatedRowHeight:FITHEIGHT(100)];
        [self.view addSubview:_tableView = tableView];
    }
    return _tableView;
}
- (UIView *)bottomView
{
    if(!_bottomView){
        UIView *view = [UIView createViewWithBackgroundColor:kCommonWhiteBg];
        
        [self.view addSubview:_bottomView = view];
        
        UIImageView *lineImageView = [UIImageView createImageViewWithName:@""];
        [view addSubview:lineImageView];
        
        [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(view);
            make.top.equalTo(view);
        }];
        UILabel *label = [UILabel createLabelWithText:[NSString stringWithFormat:@"合计:¥%@",self.totlePrice] font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#E32D2C"];
        [view addSubview:_totalLabel = label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(view);
            make.left.equalTo(view).offset(FITSCALE(30));
        }];
        ///删除按钮
        UIButton *deleteButton = [UIButton createButtonWithTitle:@"支付" backgroundNormalImage:@"" backgroundPressImage:@"" target:self action:@selector(onDeleteBlock:)];
        deleteButton.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        deleteButton.titleLabel.font = kFontSize_28;
        [deleteButton setTitleClor:kFontColorWhite];
        [view addSubview:_deleteButton = deleteButton];
        [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(view);
            make.centerY.equalTo(view);
            make.width.mas_equalTo((kMainScreenWidth - FITSCALE(190/2))/2);
            make.height.mas_equalTo(view);
        }];
        
    }
    return _bottomView;
}

@end
